home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_socket_ssl.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  2KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from test import test_support
  5. import socket
  6. import time
  7. if test_support.is_resource_enabled('network'):
  8.     pass
  9. skip_expected = not hasattr(socket, 'ssl')
  10.  
  11. def test_basic():
  12.     test_support.requires('network')
  13.     import urllib as urllib
  14.     socket.RAND_status()
  15.     
  16.     try:
  17.         socket.RAND_egd(1)
  18.     except TypeError:
  19.         pass
  20.  
  21.     print "didn't raise TypeError"
  22.     socket.RAND_add('this is a random string', 75.0)
  23.     f = urllib.urlopen('https://sf.net')
  24.     buf = f.read()
  25.     f.close()
  26.  
  27.  
  28. def test_rude_shutdown():
  29.     
  30.     try:
  31.         import thread
  32.     except ImportError:
  33.         return None
  34.  
  35.     PORT = 9934
  36.     
  37.     def listener():
  38.         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  39.         s.bind(('', PORT))
  40.         s.listen(5)
  41.         s.accept()
  42.         del s
  43.         thread.exit()
  44.  
  45.     
  46.     def connector():
  47.         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  48.         s.connect(('localhost', PORT))
  49.         
  50.         try:
  51.             ssl_sock = socket.ssl(s)
  52.         except socket.sslerror:
  53.             pass
  54.  
  55.         raise test_support.TestFailed, 'connecting to closed SSL socket failed'
  56.  
  57.     thread.start_new_thread(listener, ())
  58.     time.sleep(1)
  59.     connector()
  60.  
  61.  
  62. def test_main():
  63.     if not hasattr(socket, 'ssl'):
  64.         raise test_support.TestSkipped('socket module has no ssl support')
  65.     
  66.     test_rude_shutdown()
  67.     test_basic()
  68.  
  69. if __name__ == '__main__':
  70.     test_main()
  71.  
  72.